package manage.commons.utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import manage.commons.Constants;

/**
 * 字符串转换成inputStream,方便action 处理ajax返回
 * 
 * @author dongji
 * 
 */
public final class InputStreamUtil {

	public static InputStream toInputStream(String str) {
		String temp = str == null ? "" : str;
		try {
			return new ByteArrayInputStream(temp.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}

	public static InputStream getSuccessInputStream() {
		return toInputStream(Constants.RETURN_SUCCESS);
	}

	public static InputStream getFailedInputStream() {
		return toInputStream(Constants.RETURN_FAILED);
	}

	public static InputStream getNoChangeInputStream() {
		return toInputStream(Constants.RETURN_NO_CHANGE);
	}

	public static InputStream getExistsInputStream() {
		return toInputStream(Constants.RETURN_EXISTS);
	}

	public static InputStream getNotExistsInputStream() {
		return toInputStream(Constants.RETURN_NOT_EXISTS);
	}
}
